gusucode.com > VC 电梯管理系统 > VC 电梯管理系统/gusucode/Elevator/ElevatorDlg.cpp
//Download by http://www.NewXing.com // ElevatorDlg.cpp : implementation file // #include "stdafx.h" #include "Elevator.h" #include "ElevatorDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif /*#################################################################### 模块名称: 电梯箱体 开发作者: 漫步阳光 开发时间: @2005.11 ####################################################################*/ ///////////////////////////////////////////////////////////////////////////// // CElevatorDlg dialog CElevatorDlg::CElevatorDlg(CWnd* pParent /*=NULL*/) : CDialog(CElevatorDlg::IDD, pParent) { //{{AFX_DATA_INIT(CElevatorDlg) //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_iMaxPassengerNum = 15; m_iCurPassengerNum = 0; m_iCurFloor = 1; m_iNextDestFloor = -1; m_eCurState = IDLE; m_cUpWaitQueue =new CUpWaitQueue(); m_cDownWaitQueue =new CDownWaitQueue(); } CElevatorDlg::CElevatorDlg(int iElevatorNo, int iMaxPassengerNum/*=15*/, int iIniFloor/*=1*/, CWnd* pParent/*=NULL*/) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_iElevatorNo = iElevatorNo; m_iMaxPassengerNum = iMaxPassengerNum; m_iCurPassengerNum = 0; m_iCurFloor = iIniFloor;//电梯开始时所在楼层 m_iNextDestFloor = -1; m_eCurState = IDLE; m_eBackupDirection = BAD_DIRE; m_bCanSchedule = TRUE; m_pParent=pParent; m_cUpWaitQueue =new CUpWaitQueue(FLOOR_NUM); m_cDownWaitQueue =new CDownWaitQueue(FLOOR_NUM); stateDespArr[0] = "空闲"; stateDespArr[1] = "下行"; stateDespArr[2] = "上行"; stateDespArr[3] = "下行暂停"; stateDespArr[4] = "上行暂停"; stateDespArr[5] = "开门"; stateDespArr[6] = "故障!"; stateDespArr[7] = ""; str_arrElevatorName[0]='A'; str_arrElevatorName[1]='B'; str_arrElevatorName[2]='C'; str_arrElevatorName[3]='D'; CString tempStr; tempStr.Format("%d",iElevatorNo); tempStr = "logs\\log"+tempStr+".txt"; try{ m_cLogFile.Open( tempStr, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite\ | CFile::typeText , &m_Except);//打开日志文件 m_cLogFile.SeekToEnd(); Write2Log("空闲"); }catch(CException* e){} } void CElevatorDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CElevatorDlg) DDX_Control(pDX, IDC_STATIC_PSG_NUM, m_conPsgNum); DDX_Control(pDX, IDC_STATIC_STATE, m_conState); DDX_Control(pDX, IDC_STATIC_ELEVATOR1, m_ElevatorBox); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CElevatorDlg, CDialog) //{{AFX_MSG_MAP(CElevatorDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_TIMER() ON_WM_DESTROY() ON_BN_CLICKED(IDC_BTN_OPEN_DOOR, openDoor) ON_BN_CLICKED(IDC_BTN_CLOSE_DOOR, closeDoor) ON_BN_CLICKED(IDC_BTN_CREATE_FAULT, OnBtnCreateFault) ON_BN_CLICKED(IDC_BTN_CORRECT_FAULT, OnBtnCorrectFault) ON_BN_CLICKED(IDC_BTN_PSG_ENTER, OnBtnPsgEnter) ON_BN_CLICKED(IDC_BTN_PSG_LEAVE, OnBtnPsgLeave) ON_WM_CTLCOLOR() //}}AFX_MSG_MAP ON_COMMAND_RANGE(IDC_MYBUTTONS,IDC_MYBUTTONS+10,OnInnerBtnClk) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CElevatorDlg message handlers /*#################################################################### // name: OnInitDialog // input1: // ouput: BOOL // 功能描述: 电梯箱体初始化 // 开发作者: 漫步阳光 // 开发时间: @2005.11 // 版本说明: v1.0 ####################################################################*/ BOOL CElevatorDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here CString TempString; //===========创建动态按钮 CString strCaption; int iPanelLeft = 10; int iPanelTop = 40; int iRowHeight = 35; int iColWidth = 36; int iBtnWidth = 35; int iBtnHeight = 30; int i; try{ for(i=FLOOR_NUM;i>0;i--) { strCaption.Format("%d",i); m_pButton[i-1]=new CButton; if(i%2==0) { m_pButton[i-1]->Create(strCaption,BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,\ CRect(\ iPanelLeft,\ iPanelTop+(10-i)*iRowHeight/2,\ iPanelLeft+iBtnWidth,\ iPanelTop+(10-i)*iRowHeight/2+iBtnHeight),\ this,IDC_MYBUTTONS+i-1);//left,top,right,bottom } else { m_pButton[i-1]->Create(strCaption,BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,\ CRect(\ iPanelLeft+iColWidth,\ iPanelTop+(10-i-1)*iRowHeight/2,\ iPanelLeft+iColWidth+iBtnWidth,\ iPanelTop+(10-i-1)*iRowHeight/2+iBtnHeight),\ this,IDC_MYBUTTONS+i-1);//left,top,right,bottom } }//for }catch(CException* e){ AfxMessageBox("无法创建电梯按钮,程序不能正常运行。"); return FALSE;//退出! } GetDlgItem(IDC_BTN_OPEN_DOOR)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_CLOSE_DOOR)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_PSG_ENTER)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_PSG_LEAVE)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_CORRECT_FAULT)->EnableWindow(FALSE); //===========创建楼层号 iPanelLeft = 160; int iLabelWidth = 20; int iLabelHeight = ELEVATOR_HEIGHT; iPanelTop = 36; try{ for(i=FLOOR_NUM;i>0;i--) { TempString.Format("%d",i); m_pLabel[i-1] = new CStatic; m_pLabel[i-1]->Create(TempString+"#",WS_CHILD|WS_VISIBLE|SS_CENTER,\ CRect(\ iPanelLeft,\ iPanelTop+(10-i)*iLabelHeight,\ iPanelLeft+iLabelWidth,\ iPanelTop+(11-i)*iLabelHeight),\ this,IDC_MYLABELS+i-1); }//for }catch(CException* e){ AfxMessageBox("无法创建楼层标号,程序不能正常运行。"); return FALSE;//退出! } CFont cFont; cFont.CreateFont(12, 10, 0, 0, FW_BOLD, FALSE, TRUE,0,0,0,0,0,0, "宋体"); //m_hbrush=CreateSolidBrush(RGB(0,0,255)); TempString.Format("%c",str_arrElevatorName[m_iElevatorNo-1]); ((CButton* )GetDlgItem(IDC_STATIC_ELEVATOR))->SetFont(&cFont); ((CButton* )GetDlgItem(IDC_STATIC_ELEVATOR))->SetWindowText("电梯"+TempString); cFont.DeleteObject(); m_ElevatorBox.SetWindowText(" "); m_ElevatorBox.SetBkColor(RGB(0,0,255)); //===========电梯箱体 m_ElevatorBox.MoveWindow(iPanelLeft-70,iPanelTop+(10-m_iCurFloor)*iLabelHeight,\ 70,20); return TRUE; // return TRUE unless you set the focus to a control } void CElevatorDlg::OnSysCommand(UINT nID, LPARAM lParam) { CDialog::OnSysCommand(nID, lParam); } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CElevatorDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CElevatorDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } /*#################################################################### // name: OnTimer // input1: UINT nIDEvent // ouput: void // 功能描述: 基于定时器的电梯时序控制函数 // 开发作者: 漫步阳光 // 开发时间: @2005.11 // 版本说明: v1.0 ####################################################################*/ void CElevatorDlg::OnTimer(UINT nIDEvent) { //static int CurFloor=1; // TODO: Add your message handler code here and/or call default /* if(m_iNextDestFloor<0) //如果下一个目的楼层无效,则停止 { KillTimer(1); return; } */ switch(nIDEvent) { case 1://电梯运行控制时钟 if(m_eCurState==UP_RUN) { if(m_iCurFloor < m_iNextDestFloor) { m_iCurFloor++; m_ElevatorBox.MoveWindow(90,36+(10-m_iCurFloor)*ELEVATOR_HEIGHT,\ 70,20); } else //到达目的楼层 { KillTimer(1); buzz(); openDoor(); } }else if(m_eCurState==DOWN_RUN) { if(m_iCurFloor > m_iNextDestFloor) { m_iCurFloor--; m_ElevatorBox.MoveWindow(90,36+(10-m_iCurFloor)*ELEVATOR_HEIGHT,\ 70,20); } else //到达目的楼层 { KillTimer(1); buzz(); openDoor(); } } break; case 2://电梯开门超时控制时钟 KillTimer(2); closeDoor(); break; } CDialog::OnTimer(nIDEvent); } /*#################################################################### // name: openDoor // input1: // ouput: void // 功能描述: 电梯到达目的楼层后开门 // 开发作者: 漫步阳光 // 开发时间: @2005.11 // 版本说明: v1.0 ####################################################################*/ void CElevatorDlg::openDoor() { //如果电梯之前接受的是逆向请求,现在到达了目的楼层,则转向并解禁 if(m_eBackupDirection!=BAD_DIRE) { if(m_eBackupDirection==UP) { m_eCurState = UP_PAUSE; m_cDownWaitQueue->removeElement(m_iCurFloor); }else{ m_eCurState = DOWN_PAUSE; m_cUpWaitQueue->removeElement(m_iCurFloor); } m_bCanSchedule = TRUE; m_eBackupDirection = BAD_DIRE; }else{ //从等待队列中移除当前楼层请求 if(m_eCurState == UP_RUN){ m_cUpWaitQueue->removeElement(m_iCurFloor); m_eCurState = UP_PAUSE; } else if(m_eCurState == DOWN_RUN){ m_cDownWaitQueue->removeElement(m_iCurFloor); m_eCurState = DOWN_PAUSE; } } CString tempStr,tempStr1; tempStr.Format("%d",m_iCurFloor); tempStr = "到达"+tempStr+"楼"; m_conState.SetWindowText(tempStr); tempStr1.Format("%d",m_iCurPassengerNum); Write2Log(tempStr+"("+tempStr1+"人)");//记录日志 tempStr=""; //m_conState.SetWindowText("门开"); GetDlgItem(IDC_BTN_OPEN_DOOR)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_CLOSE_DOOR)->EnableWindow(TRUE); GetDlgItem(IDC_BTN_PSG_ENTER)->EnableWindow(TRUE); GetDlgItem(IDC_BTN_PSG_LEAVE)->EnableWindow(TRUE); enableRelateBtn(m_eCurState,m_iCurFloor); SetTimer(2,DOOR_OPEN_TIME*1000,NULL);//开启开门超时计时时钟 } /*#################################################################### // name: closeDoor // input1: // ouput: void // 功能描述: 电梯箱体关门 // 开发作者: 漫步阳光 // 开发时间: @2005.11 // 版本说明: v1.0 ####################################################################*/ void CElevatorDlg::closeDoor() { //KillTimer(2); //m_eCurState = m_eOldState; //恢复电梯运行方向 //m_conState.SetWindowText("门关"); //到头后自动换向 if(m_eCurState==UP_PAUSE && m_iCurFloor==FLOOR_NUM) m_eCurState =DOWN_PAUSE; if(m_eCurState==DOWN_PAUSE && m_iCurFloor==1) m_eCurState =UP_PAUSE; GetDlgItem(IDC_BTN_CLOSE_DOOR)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_PSG_ENTER)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_PSG_LEAVE)->EnableWindow(FALSE); //前往下一楼层 gotoNextDest(); } /*#################################################################### // name: gotoNextDest // input1: // ouput: void // 功能描述: 关门后去往下一个楼层 // 开发作者: 漫步阳光 // 开发时间: @2005.11 // 版本说明: v1.0 ####################################################################*/ void CElevatorDlg::gotoNextDest() { if(m_eCurState==UP_PAUSE) { if((m_iNextDestFloor = m_cUpWaitQueue->getNextAvail())==-1)//上行队列空,调整方向 { if(m_iCurPassengerNum>0) //如果无请求但有乘客则进入暂停状态 { //m_conState.SetWindowText("上行暂停"); }else{ m_eCurState =IDLE; //m_conState.SetWindowText("空闲"); Write2Log("空闲");//记录日志 } }else{m_eCurState =UP_RUN;} } else if(m_eCurState==DOWN_PAUSE) { if((m_iNextDestFloor = m_cDownWaitQueue->getNextAvail())==-1)//下行队列空,调整方向 { if(m_iCurPassengerNum>0) //如果无请求但有乘客则进入暂停状态 { //m_conState.SetWindowText("下行暂停"); }else{ m_eCurState =IDLE; //m_conState.SetWindowText("空闲"); Write2Log("空闲");//记录日志 } }else{m_eCurState =DOWN_RUN;} } m_conState.SetWindowText(stateDespArr[m_eCurState]);//改变电梯状态显示 //如果找到了下一个请求 if(m_iNextDestFloor >0) SetTimer(1,ONE_FLOOR_TIME*1000,NULL);//启动电梯 } /*#################################################################### // name: OnInnerBtnClk // input1: UINT curBtn // ouput: void // 功能描述: 响应电梯内按钮的动作 // 开发作者: 漫步阳光 // 开发时间: @2005.11 // 版本说明: v1.0 ####################################################################*/ void CElevatorDlg::OnInnerBtnClk(UINT curBtn) { if(m_iCurPassengerNum==0) { AfxMessageBox("请先按右边楼层按钮请求电梯。"); return; } if(isMalFunction()) { AfxMessageBox("本电梯故障。"); return; } int iReqFloor = curBtn-900+1; if((m_eCurState==UP_RUN && iReqFloor<=m_iCurFloor) || \ (m_eCurState==UP_PAUSE && iReqFloor<m_iCurFloor)) { AfxMessageBox("您的请求跟电梯当前运行方向不一致。"); return; }else if((m_eCurState==DOWN_RUN && iReqFloor>=m_iCurFloor) || \ (m_eCurState==DOWN_PAUSE && iReqFloor>m_iCurFloor)) { AfxMessageBox("您的请求跟电梯当前运行方向不一致。"); return; } //如果刚好电梯所停楼层有请求,则直接开门 if((m_eCurState==UP_PAUSE || m_eCurState==DOWN_PAUSE) && (iReqFloor==m_iCurFloor)) { if(m_eCurState==UP_PAUSE) m_eCurState = UP_RUN; else m_eCurState = DOWN_RUN; buzz(); openDoor(); return; } switch(m_eCurState) { case UP_PAUSE: m_iNextDestFloor = m_cUpWaitQueue->getNextAvail(); if(m_iNextDestFloor==-1 || iReqFloor<m_iNextDestFloor) m_iNextDestFloor = iReqFloor; m_cUpWaitQueue->addElement(iReqFloor); m_eCurState =UP_RUN; //m_conState.SetWindowText("上行"); KillTimer(1); SetTimer(1,ONE_FLOOR_TIME*1000,NULL);//启动电梯 break; case DOWN_PAUSE: m_iNextDestFloor = m_cDownWaitQueue->getNextAvail(); if(m_iNextDestFloor==-1 || iReqFloor>m_iNextDestFloor) m_iNextDestFloor = iReqFloor; m_cDownWaitQueue->addElement(iReqFloor); m_eCurState =DOWN_RUN; //m_conState.SetWindowText("下行"); KillTimer(1); SetTimer(1,ONE_FLOOR_TIME*1000,NULL);//启动电梯 break; case UP_RUN: if(iReqFloor<m_iNextDestFloor) m_iNextDestFloor = iReqFloor; m_cUpWaitQueue->addElement(iReqFloor); break; case DOWN_RUN: if(iReqFloor>m_iNextDestFloor) m_iNextDestFloor = iReqFloor; m_cDownWaitQueue->addElement(iReqFloor); break; } m_conState.SetWindowText(stateDespArr[m_eCurState]);//改变电梯状态显示 GetDlgItem(IDC_MYBUTTONS+iReqFloor-1)->EnableWindow(FALSE); } void CElevatorDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here for(int i=0;i<FLOOR_NUM;i++) { delete m_pButton[i]; delete m_pLabel[i]; } /* delete[] m_pButton; delete[] m_pLabel; delete[] stateDespArr; */ try{ m_cLogFile.Close(); }catch(CException* e){} KillTimer(1);KillTimer(2); } void CElevatorDlg::OnBtnCreateFault() { // TODO: Add your control notification handler code here if(m_eCurState==UP_RUN || m_eCurState==DOWN_RUN) { AfxMessageBox("电梯正在运行中,不允许出现故障!"); return; } if(m_iCurPassengerNum > 0) { AfxMessageBox("电梯当前有乘客,不允许出现故障!"); return; } m_eOldState = m_eCurState; m_eCurState =MAL_FUNCTION; GetDlgItem(IDC_BTN_CREATE_FAULT)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_CORRECT_FAULT)->EnableWindow(TRUE); m_conState.SetWindowText(stateDespArr[m_eCurState]);//改变电梯状态显示 Write2Log("产生故障!");//记录日志 } void CElevatorDlg::OnBtnCorrectFault() { // TODO: Add your control notification handler code here m_eCurState =m_eOldState; GetDlgItem(IDC_BTN_CREATE_FAULT)->EnableWindow(TRUE); GetDlgItem(IDC_BTN_CORRECT_FAULT)->EnableWindow(FALSE); m_conState.SetWindowText(stateDespArr[m_eCurState]);//改变电梯状态显示 Write2Log("故障已修复");//记录日志 } void CElevatorDlg::OnBtnPsgEnter() { // TODO: Add your control notification handler code here if(isOverWeight()) { AfxMessageBox("本电梯已达到最大负重,不能再进人。"); return; } m_iCurPassengerNum++; CString TempStr =""; TempStr.Format("%d",m_iCurPassengerNum); m_conPsgNum.SetWindowText("内有人数:"+TempStr); Write2Log("进一人"); } void CElevatorDlg::OnBtnPsgLeave() { // TODO: Add your control notification handler code here if(m_iCurPassengerNum==0) { AfxMessageBox("本电梯内当前无乘客。"); return; } m_iCurPassengerNum--; CString TempStr =""; TempStr.Format("%d",m_iCurPassengerNum); m_conPsgNum.SetWindowText("内有人数:"+TempStr); Write2Log("出一人"); } /*#################################################################### // name: acceptReq // input1: sOuterRequest& tmpOuterRequest 请求结构体 // ouput: void // 功能描述: 接收主控中心发来的楼层请求 // 开发作者: 漫步阳光 // 开发时间: @2005.11 // 版本说明: v1.0 ####################################################################*/ void CElevatorDlg::acceptReq(sOuterRequest& tmpOuterRequest) { enum direction eReqDirection = tmpOuterRequest.eReqDirection; int iReqFloor = tmpOuterRequest.iReqFloor; //如果刚好电梯所停楼层有请求,则直接开门 if((m_eCurState==IDLE || m_eCurState==UP_PAUSE || m_eCurState==DOWN_PAUSE) && iReqFloor == m_iCurFloor) { if(eReqDirection==UP) m_eCurState = UP_RUN; else m_eCurState = DOWN_RUN; buzz(); openDoor(); return; } enum direction realDire = (iReqFloor>m_iCurFloor) ? UP : DOWN; switch(m_eCurState) { case IDLE: //记录用户请求方向与电梯应该运行方向不一致的情况,以便电梯到达后调整方向 if(eReqDirection==UP && realDire==DOWN){ m_eBackupDirection = UP; m_bCanSchedule = FALSE;//电梯在到达本请求楼层前不允许再被调度 }else if(eReqDirection==DOWN && realDire==UP){ m_eBackupDirection = DOWN; m_bCanSchedule = FALSE;//电梯在到达本请求楼层前不允许再被调度 } if(realDire==UP) { m_eCurState =UP_RUN; m_cUpWaitQueue->addElement(iReqFloor); }else{ m_eCurState =DOWN_RUN; m_cDownWaitQueue->addElement(iReqFloor); } m_conState.SetWindowText(stateDespArr[m_eCurState]);//改变电梯状态显示 Write2Log(stateDespArr[m_eCurState]);//记录日志 m_iNextDestFloor = iReqFloor; KillTimer(1); SetTimer(1,ONE_FLOOR_TIME*1000,NULL);//启动电梯 break; case UP_PAUSE: m_iNextDestFloor = m_cUpWaitQueue->getNextAvail(); if(m_iNextDestFloor==-1 || iReqFloor<m_iNextDestFloor) m_iNextDestFloor = iReqFloor; m_cUpWaitQueue->addElement(iReqFloor); m_eCurState =UP_RUN; m_conState.SetWindowText(stateDespArr[m_eCurState]);//改变电梯状态显示 KillTimer(1); SetTimer(1,ONE_FLOOR_TIME*1000,NULL);//启动电梯 break; case DOWN_PAUSE: m_iNextDestFloor = m_cDownWaitQueue->getNextAvail(); if(m_iNextDestFloor==-1 || iReqFloor>m_iNextDestFloor) m_iNextDestFloor = iReqFloor; m_cDownWaitQueue->addElement(iReqFloor); m_eCurState =DOWN_RUN; m_conState.SetWindowText(stateDespArr[m_eCurState]);//改变电梯状态显示 KillTimer(1); SetTimer(1,ONE_FLOOR_TIME*1000,NULL);//启动电梯 break; case UP_RUN: if(iReqFloor<m_iNextDestFloor) m_iNextDestFloor = iReqFloor; m_cUpWaitQueue->addElement(iReqFloor); break; case DOWN_RUN: if(iReqFloor>m_iNextDestFloor) m_iNextDestFloor = iReqFloor; m_cDownWaitQueue->addElement(iReqFloor); break; } } void CElevatorDlg::enableRelateBtn(enum state eCurState, int iFloorNo) { //Enable当前楼层按钮 GetDlgItem(IDC_MYBUTTONS+iFloorNo-1)->EnableWindow(TRUE); //通知父窗体Enable该楼层按钮 int tarFloorBtnID = (eCurState==UP_PAUSE) ? (2*(iFloorNo-1)) : (2*(iFloorNo-1)+1); m_pParent->SendMessage(WM_ARRIVE_ONEFLOOR,(WPARAM)tarFloorBtnID); } void CElevatorDlg::Write2Log(CString content) { CString tempStr; tempStr.Format("%d",m_iElevatorNo); CTime m_SysTime = CTime::GetCurrentTime(); try{ m_cLogFile.WriteString("电梯"+tempStr+" ["+content+"]\t("+m_SysTime.Format("%Y-%m-%d %H:%M:%S")+")\n"); }catch(CException* e){} } void CElevatorDlg::buzz() { MessageBeep(MB_ICONASTERISK); } HBRUSH CElevatorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here // TODO: Return a different brush if the default is not desired /* if(nCtlColor== CTLCOLOR_STATIC) { pDC->SetBkMode(TRANSPARENT); //此处设置字体的颜色 pDC->SetTextColor(RGB(0,0,255)); return m_hbrush; } else */ return hbr; }